<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/7
 * Time: 13:25
 */
$router = new AltoRouter();

$router->setBasePath('');

$router->map('GET','/view',function (){
	echo 'view sucess!';
});

$router->map('GET','/users/', array('c' => 'UserController', 'a' => 'ListAction'));
$router->map('GET','/demo/[i:id]/[a:name]','App\Demo\Controllers\HomeController#home','demoName');

//$router->map('GET','/','IndexController#Doo');

$match = $router->match();
var_dump($match);
//var_dump(explode('#',$match['target']));
// call closure or throw 404 status


if ($match)
{
	if (is_callable($match['target']))
	{
		call_user_func_array( $match['target'], $match['params'] );
	}else{
		$controller_method=explode('#',$match['target']);
		$controller = new $controller_method[0]();
		call_user_func_array(array($controller,$controller_method[1]),$match['params']);
	}
}else{
	echo '404 Not Found';
}


echo $router->generate('demoName',array('id' => 10, 'name' => 'update'));

/**
if( $match && is_callable( $match['target'] ) ) {
	call_user_func_array( $match['target'], $match['params'] );
	//var_dump($match);
} else {
	// no route was matched
	//header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
	echo '404 Not Found';
}
 **/